package com.demo.index;



import java.io.File;

import com.demo.common.model.Data;
import com.jfinal.core.Controller;
import com.jfinal.kit.PathKit;

import net.unix8.tool.SQLExec;

/**
 * IndexController
 */
public class IndexController extends Controller {
	public void clear(){
		SQLExec.clear();
		renderText("Delete SQL Table Success\n");
	}
	public void index() {
		String fileString = getPara("filename",null).trim();
		System.out.println(fileString);  
		String pathString = getPara("hostname").trim();
		System.out.println(pathString);  
		System.out.println( PathKit.getWebRootPath());  

		String dataSaveString = PathKit.getWebRootPath() + "/data/" + pathString+"/"+fileString;
		System.out.println(dataSaveString);  
		File file =new File(dataSaveString);    
		if  (file.exists() && !file.isDirectory())      
		{       
			renderFile(file);
		} else{
			renderError(404);
		}
	}
	public void source() {
		//String fileString = "source";
		String fileString = getPara("filename",null).trim();
		String dataSaveString = PathKit.getWebRootPath() + "/pdata/" +fileString;
		//System.out.println(dataSaveString);  
		File file =new File(dataSaveString);    
		if  (file.exists() && !file.isDirectory())      
		{       
			renderFile(file);
		} else{
			renderError(404);
		}
	}
	public void gps() {
		//String fileString = "source";
		String pathString = getPara("hostname").trim();
		String dataSaveString = PathKit.getWebRootPath() + "/pdata/"+pathString+"/gps_location";
		File file =new File(dataSaveString);    
		if  (file.exists() && !file.isDirectory())      
		{       
			renderFile(file);
		} else{
			renderError(404);
		}
	}
	public void mtime() {
		//String fileString = "source";
		String fileString = getPara("filename",null).trim();
		String dataSaveString = PathKit.getWebRootPath() + "/tmp/" +fileString;
		File file =new File(dataSaveString);    
		if  (file.exists() && !file.isDirectory())      
		{       
			renderFile(file);
		} else{
			renderError(404);
		}
	}
	
	public void saveData(){
		//int id = getParaToInt(0);
		String hash = getPara("hash");
		int  s_no = getParaToInt("s_no");
		int  s_channels = getParaToInt("s_channels");
		int  s_rate = getParaToInt("s_rate");
		long  s_collect_s_time = getParaToLong("s_collect_s_time");
		long  s_collect_e_time = getParaToLong("s_collect_e_time");
		String s_file_path = getPara("s_file_path");		
		String s_file_md5 = getPara("s_file_md5");
		
		int  s_file_size = getParaToInt("s_file_size");
		int  s_valied = getParaToInt("s_valied");
		long  s_create_time = getParaToLong("s_create_time");

		String s_file_format = getPara("s_file_format");
		String s_note = getPara("s_note");
		if(Data.dao.set(hash, hash)
		.set("hash", hash)
		.set("s_no", hash)
		.set("s_channels", hash)
		.set("s_rate", hash)
		.set("s_collect_s_time", hash)
		.set("s_collect_e_time", hash)
		.set("s_file_path", hash)
		.set("s_file_md5", hash)
		.set("s_file_size", hash)
		.set("s_valied", hash)
		.set("s_create_time", hash)
		.set("s_file_format", hash)
		.set("s_note", hash)
		.save()){
			
		}
	}
}





